package com.xh.clean.modular.clean.warpper;

import com.xh.clean.core.base.warpper.BaseControllerWarpper;
import com.xh.clean.core.common.constant.factory.ConstantFactory;
import com.xh.clean.core.util.ToolUtil;
import com.xh.clean.modular.clean.model.PatrolArea;
import com.xh.clean.modular.system.model.User;
import com.xh.clean.modular.system.model.User;

import java.util.Map;

/**
 * 巡查记录包装
 *
 * @author 杨杰
 * @create 2018-06-24 20:48
 **/
public class PatrolWarpper extends BaseControllerWarpper {
    public PatrolWarpper(Object obj) {
        super(obj);
    }

    @Override
    protected void warpTheMap(Map<String, Object> map) {
        String remark = (String) map.get("remark");
        Integer userid = (Integer) map.get("creater");
        Integer pareaId = (Integer) map.get("pareaId");
        User user = ConstantFactory.me().getUserById(userid);
        if (user != null) {
            map.put("roleName", ConstantFactory.me().getRoleName(user.getRoleid()));
            map.put("userName", user.getName());
        }
        PatrolArea patrolArea = ConstantFactory.me().getPatrolAreaById(pareaId);
        if (patrolArea != null) {
            map.put("pareaName", patrolArea.getName());
            Integer storeyId = patrolArea.getStoreyId();
            map.put("storeyName", ConstantFactory.me().getStoreyNameById(storeyId));
            Integer type = patrolArea.getType();
            map.put("typeName", ConstantFactory.me().getDictName(type));
            map.put("position", patrolArea.getPosition());
        }
        //如果信息过长,则只截取前100位字符串
        if (ToolUtil.isNotEmpty(remark) && remark.length() >= 100) {
            String subMessage = remark.substring(0, 100) + "...";
            map.put("remark", subMessage);
        }

//        //如果信息中包含分割符号;;;   则分割字符串返给前台
//        if (ToolUtil.isNotEmpty(remark) && remark.indexOf(Contrast.separator) != -1) {
//            String[] msgs = remark.split(Contrast.separator);
//            map.put("regularMessage",msgs);
//        }else{
//            map.put("regularMessage",remark);
//        }
    }
}
